********************************************************************************
*                         Analysis of Estonia Experiment                       *
********************************************************************************

* Code by Paul Musgrave (musgrave@umass.edu)
* For Paul Musgrave and Lindsey Guenther
* 2022-April-17

* README: This code takes the cleaned data from the NATO Cyber Experiments
* conducted in April 2021 and turns them into a series of tables and charts
* for use in an appendix and manuscript.


********************************************************************************
*                                   Stata Stuff                                *
********************************************************************************

clear all

set more off

set scheme plotplainblind


global MyDocs "/Users/paulmusgrave/Dropbox/0001 Academic Projects/Ongoing/"
global MyProject "${MyDocs}0151 Lindsey NATO Cyber/Posted/Dataverse"

use "${MyProject}/apsaestonia.dta"

gen     knowstable = knowstable1 + knowstable2
lab var knowstable "Knowledge (Stable)"

gen     knowscan = knowscan1 + knowscan2
lab var knowscan "Knowledge (Scan)"

gen     knowcheat = cheat1 + cheat2
lab var knowcheat "Knowledge (Cheat)"

********************************************************************************
*                       Organizing Code / Macros                               *
********************************************************************************

local demographics			 age white female hispanic college i.pid7 veteran
local economics          i.hhi i.employment
local technical				   attntotal order mobile
local trust              trustfeds
local feelings           raterussia rateestonia
local news               newsoftenalt newsimportantalt newspersonality
local internationalism   mi ci iso
local knowledge          knowscan knowstable knowcheat

********************************************************************************
*                       Core Analysis
********************************************************************************

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*					Analysis of Support, Multinomial logit
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Brant tests show an ordinal logit is inappropriate, so we move on to
* Multinomial logit
eststo h1m1: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            , base(1)
eststo h1m2: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
eststo h1m3: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `news' `knowledge' ///
                            , base(1)
eststo h1m4: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `trust' `feds' ///
                            , base(1)
eststo h1m5: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `internationalism' `feelings' ///
                            , base(1)
eststo h1m6: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `internationalism' `feelings' ///
                            if attntotal == 3, base(1)							
******** Tables
esttab 	h1m1 h1m2 h1m3 h1m4 h1m5 using "${MyProject}/EstoniaTableH1Mlogit.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment, Main DV, Logit" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Casualty Type" ///
                1.estoniaplausible "Russian Attribution" ///
                age "Demographics" ///
                , nolabel)

********* Main charts *********************************************************

* * * * * * * * * * * * * * Coefficient Plots

coefplot  (h1m1, label(Base, No Controls) offset(.3)) ///
          (h1m2, label(Base With Controls) offset(.2)) ///
          (h1m3, label(Knowledge) offset(.1)) ///
          (h1m4, label(Trust)) ///
          (h1m5, label(Internationalism) offset(-0.1)) ///
		  (h1m6, label(Attentive Only) offset(-0.2)), drop(_cons) ///
          keep(Oppose:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({it:Predict Oppose}, size(medium) span) ///
          caption("N: Base = 1405, Internationalism = 1134, Attentive = 949, others = 1344." ///
            , size(vsmall)) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefoppose,replace) legend(rows(2) ring(2) pos(12))

coefplot  (h1m1, label(Base, No Controls) offset(.3)) ///
          (h1m2, label(Base With Controls) offset(.2)) ///
          (h1m3, label(Knowledge) offset(.1)) ///
          (h1m4, label(Trust)) ///
          (h1m5, label(Internationalism) offset(-0.1)) , drop(_cons) ///
          keep(Support:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({it:Predict Support}, size(medium) span) ///
          caption("N: Base = 1405, Internationalism = 1134, Attentive = 949, others = 1344." ///
            , size(vsmall)) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefsupport,replace) legend(rows(2) ring(2) pos(12))

grc1leg2 coefoppose coefsupport, ///
          rows(2) lrows(3) ring(2) position(6) labsize(vsmall) ///
          name(coefcombined, replace)  ///
          title({bf:A: Estonia Scenario Model Results}, nospan size(medium)) ///
          subtitle({it:Multinomial Logistic Coefficients Shown; Base is Neither}, size(small)) ///
          xcommon
graph display coefcombined,  ysize(6) xsize(6)

* * * * * * * * * * * * * * Effect Size Plots

mylabels 0(10)80, myscale(@/100) local(myla)
quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins estoniaplausible, atmeans
marginsplot, title("") ///
             subtitle({it:By Plausibility of Russian Involvement; Other Variables at Means}) ///
             plotdim(,elabels(1 "Oppose" 2 "Neither" 3 "Support")) ylab(`myla') ///
             name(h1estoniaplausible, replace) nodraw

mylabels 0(10)50, myscale(@/100) local(myla)
quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins estoniacivilian, atmeans
marginsplot, title("") ///
             subtitle({it:By Casualties; Other Variables at Means}) ///
             plotdim(,elabels(1 "Oppose" 2 "Neither" 3 "Support")) ylab(`myla') ///
             name(h1estoniacivilian, replace) nodraw
grc1leg2 h1estoniaplausible h1estoniacivilian , ///
          rows(2) lrows(3) ring(2) position(6) ///
          name(predictcombined,replace) ///
          title({bf: B: Predicted Outcomes for Estonia Scenario}, size(medium))
graph display predictcombined,  ysize(6) xsize(4)

graph combine coefcombined predictcombined, name(combined,replace)
graph display combined, ysize(8) xsize(10)
graph export "${MyProject}/EstoniaCombinedGraph.png", replace
graph export "${MyProject}/EstoniaCombinedGraph.pdf", replace


* * * * * * * * * * * * * * Effect Size Plots (Bar Chart Version)
quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins, atmeans at(estoniaplausible==1) post
eststo estplaus01

quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins, atmeans at(estoniaplausible==0) post
eststo estplaus00

quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins, atmeans at(estoniaplausible==2) post
eststo estplaus02

coefplot  estplaus00 estplaus01 estplaus02, ///
             subtitle({it:By Plausibility of Russian Involvement; Other Variables at Means}, span) ///
	recast(bar) barw(0.15) ///
	ciopts(recast(rcap) color(gs8)) citop ///
	 ylab(1 "Oppose" 2 "Neither" 3 "Support") ///
	legend(order(1 "Highly implausible" 3 "Somewhat Plausible" 5 "Highly Plausible") ring(0) pos(3)) ///
	xtitle("Predicted Probability of Choosing Each Response") ///
	name(estoniaplausiblebar, replace) xlab(`myla') 


quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins, atmeans at(estoniacivilian==0) post
eststo estcasualties00


quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins, atmeans at(estoniacivilian==1) post
eststo estcasualties01

* title({bf:Predicted Support for Assisting Estonia}, size(large) span) ///

coefplot estcasualties00 estcasualties01, ///
             subtitle({it:By Casualty Type; Other Variables at Means},span) ///
	recast(bar) barw(0.15) ///
	ciopts(recast(rcap) color(gs8)) citop ///
	 ylab(1 "Oppose" 2 "Neither" 3 "Support") ///
	legend(order(1 "Military" 3 "Civilian" ) ring(0) pos(3)) ///
	xtitle("Predicted Probability of Choosing Each Response") ///
	name(estoniacasualtybar, replace) xlab(`myla') 
	
gr combine estoniaplausiblebar estoniacasualtybar , ///
          name(predictcombinedbar,replace) ///
		  rows(2) ///
          title({bf: B: Predicted Outcomes for Estonia Scenario}, size(medium))	
		  
graph combine coefcombined predictcombinedbar, name(combinedbar,replace)
graph export "${MyProject}/EstoniaCombinedGraphBar.png", replace
graph export "${MyProject}/EstoniaCombinedGraphBar.pdf", replace
graph export "${MyProject}/EstoniaCombinedGraphBar.eps", replace


* * * * * * * * * * * * * * Subgroup plots

*** veteran
eststo h1m2temp0: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if veteran == 1, base(1)
eststo h1m2temp1: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if veteran == 2, base(1)
coefplot  (h1m2temp0, label(Not Veteran) offset(.1)) ///
          (h1m2temp1, label(Veteran) offset(-.1)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Oppose:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Oppose}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefopposetemp,replace) legend(rows(2) ring(2) pos(12))
coefplot  (h1m2temp0, label(Not Veteran) offset(.1)) ///
          (h1m2temp1, label(Veteran) offset(-.1)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Support:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Support}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefsupporttemp,replace) legend(rows(2) ring(2) pos(12))
grc1leg2 coefopposetemp coefsupporttemp, ///
          rows(2) lrows(1) ring(2) position(6) labsize(tiny) ///
          name(coefcombinedveteran, replace)  ///
          title({bf:Veteran}, nospan size(small)) xcommon
		  

*** female
eststo h1m2temp0: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if female == 0, base(1)
eststo h1m2temp1: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if female == 1, base(1)
coefplot  (h1m2temp0, label(Not female) offset(.1)) ///
          (h1m2temp1, label(female) offset(-.1)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Oppose:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Oppose}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefopposetemp,replace) legend(rows(2) ring(2) pos(12))
coefplot  (h1m2temp0, label(Not female) offset(.1)) ///
          (h1m2temp1, label(female) offset(-.1)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Support:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Support}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefsupporttemp,replace) legend(rows(2) ring(2) pos(12))
grc1leg2 coefopposetemp coefsupporttemp, ///
          rows(2) lrows(1) ring(2) position(6) labsize(tiny) ///
          name(coefcombinedfemale, replace)  ///
          title({bf:Gender}, nospan size(small)) xcommon

*** know
gen know = knowscan + knowstable

eststo h1m2temp0: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if know <= 1, base(1)
eststo h1m2temp1: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if know > 1, base(1)
coefplot  (h1m2temp0, label(Not knowledgeable) offset(.1)) ///
          (h1m2temp1, label(Knowledgeable) offset(-.1)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Oppose:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Oppose}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefopposetemp,replace) legend(rows(2) ring(2) pos(12))
coefplot  (h1m2temp0, label(Not knowledgeable) offset(.1)) ///
          (h1m2temp1, label(Knowledgeable) offset(-.1)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Support:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Support}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefsupporttemp,replace) legend(rows(2) ring(2) pos(12))
grc1leg2 coefopposetemp coefsupporttemp, ///
          rows(2) lrows(1) ring(2) position(6) labsize(tiny) ///
          name(coefcombinedknow, replace)  ///
          title({bf:Knowledge}, nospan size(small)) xcommon

*** PID
eststo h1m2temp0: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if pid3 == 0, base(1)
eststo h1m2temp1: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                             if pid3 == 1, base(1)
eststo h1m2temp2: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            if pid3 == 2, base(1)

coefplot  (h1m2temp0, label(Democratic) offset(.15)) ///
          (h1m2temp1, label(Independent) offset(0)) ///
          (h1m2temp2, label(Republican) offset(-.15)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Oppose:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Oppose}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefopposetemp,replace) legend(rows(2) ring(2) pos(12))
coefplot  (h1m2temp0, label(Democratic) offset(.15)) ///
          (h1m2temp1, label(Independent) offset(0)) ///
          (h1m2temp2, label(Republican) offset(-.15)) ///
          , drop(_cons) coeflabels(,labsize(tiny)) nodraw ///
          keep(Support:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Support}, size(vsmall) span) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefsupporttemp,replace) legend(rows(2) ring(2) pos(12))
grc1leg2 coefopposetemp coefsupporttemp, ///
          rows(2) lrows(1) ring(2) position(6) labsize(tiny) ///
          name(coefcombinedpid3, replace)  ///
          title({bf:Party ID}, nospan size(small)) xcommon

gr combine  coefcombinedpid3 coefcombinedknow coefcombinedveteran ///
            coefcombinedfemale, rows(2) title(Subgroup Variation) ///
            name(combinesubgroup, replace)
gr display  combinesubgroup, xsize(8) ysize(8)
graph export "${MyProject}/EstoniaSubgroupGraph.png", replace
graph export "${MyProject}/EstoniaSubgroupGraph.pdf", replace
graph close _all


* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*					Analysis of Support, Logit
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


eststo h1m1a: quietly logit estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible
eststo h1m2a: quietly logit estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical'
eststo h1m3a: quietly logit estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `news' `knowledge'
eststo h1m4a: quietly logit estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `trust' `feds'
eststo h1m5a: quietly logit estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `internationalism' `feelings'

esttab 	h1m1a h1m2a h1m3a h1m4a h1m5a using "${MyProject}/EstoniaTableH1Logit.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment, Main DV, Logit" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)

esttab 	h1m1a h1m2a h1m3a h1m4a h1m5a using "${MyProject}/EstoniaTableH1Logit.rtf", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment Testing Hypotheses 1 and 2, Main DV" \label{tab:estoniah1}) ///
        eqlabel(none)  notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*					Analysis of Support, OLS
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


eststo h1m1b: quietly reg estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible
eststo h1m2b: quietly reg estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical'
eststo h1m3b: quietly reg estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `news' `knowledge'
eststo h1m4b: quietly reg estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `trust' `feds'
eststo h1m5b: quietly reg estoniasupport_dichot1 i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' `internationalism' `feelings'


esttab 	h1m1b h1m2b h1m3b h1m4b h1m5b using "${MyProject}/EstoniaTableH1OLS.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment, Dichotomous Main DV, OLS" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)


esttab 	h1m1b h1m2b h1m3b h1m4b h1m5b using "${MyProject}/EstoniaTableH1OLS.rtf", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment Testing Hypotheses 1 and 2, Main DV" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)


********************************************************************************
*                       Interaction Analysis
********************************************************************************



* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*					Analysis of Support, Multinomial logit
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Brant tests show an ordinal logit is inappropriate, so we move on to
* Multinomial logit
eststo h1m1: quietly mlogit estoniasupport_cat i.estoniacivilian##i.estoniaplausible ///
                            , base(1)
eststo h1m2: quietly mlogit estoniasupport_cat i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
eststo h1m3: quietly mlogit estoniasupport_cat i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `news' `knowledge' ///
                            , base(1)
eststo h1m4: quietly mlogit estoniasupport_cat i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `trust' `feds' ///
                            , base(1)
eststo h1m5: quietly mlogit estoniasupport_cat i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `internationalism' `feelings' ///
                            , base(1)

esttab 	h1m1 h1m2 h1m3 h1m4 h1m5 using "${MyProject}/EstoniaTableH1MlogitInt.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment Testing, Main DV Categorical, Mlogit" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Casualty Type" ///
                1.estoniaplausible "Russian Attribution" ///
                age "Demographics" ///
                , nolabel)


coefplot  (h1m1, label(Base, No Controls) offset(.3)) ///
          (h1m2, label(Base With Controls) offset(.2)) ///
          (h1m3, label(Knowledge) offset(.1)) ///
          (h1m4, label(Trust)) ///
          (h1m5, label(Internationalism) offset(-0.1)) , drop(_cons) ///
          keep(Oppose:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Oppose}, size(medium) span) ///
          caption("N of 1344 for all models except for Internationalism, which has 1134." ///
            , size(vsmall)) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefoppose,replace) legend(rows(2) ring(2) pos(12))

coefplot  (h1m1, label(Base, No Controls) offset(.3)) ///
          (h1m2, label(Base With Controls) offset(.2)) ///
          (h1m3, label(Knowledge) offset(.1)) ///
          (h1m4, label(Trust)) ///
          (h1m5, label(Internationalism) offset(-0.1)) , drop(_cons) ///
          keep(Support:*.estoniacivilian *.estoniaplausible) ///
          noomitted nobase xline(0) ///
          title({bf:Predict Support}, size(medium) span) ///
          caption("N of 1344 for all models except for Internationalism, which has 1134." ///
            , size(vsmall)) ///
          headings(1.estoniaplausible = "{bf:Russia Attribution}" ///
            1.estoniacivilian = "{bf:Casualty Type}") ///
            name(coefsupport,replace) legend(rows(2) ring(2) pos(12))

grc1leg2 coefoppose coefsupport, ///
          rows(2) lrows(3) ring(2) position(6) labsize(vsmall) ///
          name(coefcombined, replace)  ///
          title({bf: A: Estonia Scenario Model Results}, nospan size(medium)) ///
          subtitle({it:Multinomial Logistic Coefficients Shown; Base is Neither}, size(small)) ///
          xcommon
graph display coefcombined,  ysize(6) xsize(6)


mylabels 0(10)80, myscale(@/100) local(myla)
quietly mlogit estoniasupport_cat i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins estoniaplausible, atmeans
marginsplot, title("") ///
             subtitle({it:By Plausibility of Russian Involvement; Other Variables at Means}) ///
             plotdim(,elabels(1 "Oppose" 2 "Neither" 3 "Support")) ylab(`myla') ///
             name(h1estoniaplausible, replace) nodraw

mylabels 0(10)50, myscale(@/100) local(myla)
quietly mlogit estoniasupport_cat i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins estoniacivilian, atmeans
marginsplot, title("") ///
             subtitle({it:By Casualties; Other Variables at Means}) ///
             plotdim(,elabels(1 "Oppose" 2 "Neither" 3 "Support")) ylab(`myla') ///
             name(h1estoniacivilian, replace) nodraw
grc1leg2 h1estoniaplausible h1estoniacivilian , ///
          rows(2) lrows(3) ring(2) position(6) ///
          name(predictcombined,replace) ///
          title({bf:Predicted Outcomes for Estonia Scenario}, size(medium))
graph display predictcombined,  ysize(6) xsize(4)

graph combine coefcombined predictcombined, name(combined,replace)
graph display combined, ysize(8) xsize(10)
graph export "${MyProject}/EstoniaCombinedGraphInt.png", replace
graph export "${MyProject}/EstoniaCombinedGraphInt.pdf", replace

graph close



* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*					Analysis of Support, Logit
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


eststo h1m1a: quietly logit estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible
eststo h1m2a: quietly logit estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical'
eststo h1m3a: quietly logit estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `news' `knowledge'
eststo h1m4a: quietly logit estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `trust' `feds'
eststo h1m5a: quietly logit estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `internationalism' `feelings'

esttab 	h1m1a h1m2a h1m3a h1m4a h1m5a using "${MyProject}/EstoniaTableH1LogitInt.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment, Main DV Dichotomous, Logit" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)

esttab 	h1m1a h1m2a h1m3a h1m4a h1m5a using "${MyProject}/EstoniaTableH1LogitInt.rtf", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment Testing Hypotheses 1 and 2, Main DV" \label{tab:estoniah1}) ///
        eqlabel(none)  notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*					Analysis of Support, OLS
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

eststo h1m1b: quietly reg estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible
eststo h1m2b: quietly reg estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical'
eststo h1m3b: quietly reg estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `news' `knowledge'
eststo h1m4b: quietly reg estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `trust' `feds'
eststo h1m5b: quietly reg estoniasupport_dichot1 i.estoniacivilian##i.estoniaplausible ///
                            `demographics' `economics' `technical' `internationalism' `feelings'


esttab 	h1m1b h1m2b h1m3b h1m4b h1m5b using "${MyProject}/EstoniaTableH1OLSInt.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment, Main DV Dichotomous, OLS" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)


esttab 	h1m1b h1m2b h1m3b h1m4b h1m5b using "${MyProject}/EstoniaTableH1OLSInt.rtf", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment Testing Hypotheses 1 and 2, Main DV" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes ///
        refcat( 1.estoniacivilian "Russia Attribution" ///
                1.estoniaplausible "Russian Reaction" ///
                age "Demographics" ///
                , nolabel)


********************************************************************************
*                       Counterfactual Analysis
********************************************************************************

gen     e_plausible   = estoniasupport_dichot1  if estoniaplausible     == 2
gen     e_somewhat    = estoniasupport_dichot1  if estoniaplausible     == 1
gen     e_implausible = estoniasupport_dichot1  if estoniaplausible     == 0

replace e_plausible   = estoniaalt_dichot1      if estoniaplausiblealt  == 2 & e_plausible == .
replace e_somewhat    = estoniaalt_dichot1      if estoniaplausiblealt  == 1 & e_somewhat == .
replace e_implausible = estoniaalt_dichot1      if estoniaplausiblealt  == 0 & e_implausible == .

gen     e_change_cf =  e_plausible-e_implausible
replace e_change_cf =  e_plausible-e_somewhat   if e_change_cf == .
replace e_change_cf =  e_somewhat-e_implausible if e_change_cf == .

* absolute value of treatment difference
* subtracting one to make this semi clearly interpretable, but
* there is a trick here: there are no true "zeroes" -- the question
* is of going from the top to the bottom of the scale, so a
* "1" as adjusted here actually means the contrast between the top levels!!!!
gen     estoniacf = abs(estoniaplausible - estoniaplausiblealt) - 1
lab var estoniacf "Counterfactual Treatment"
* variable to record whether this is a step down (not all unit changes are
* created equal)
* we are interested in anchoring
gen     estoniacfdecline = 0
replace estoniacfdecline = 1 if estoniaplausible > estoniaplausiblealt
lab var estoniacfdecline "Counterfactual Declining"
reg     e_change_cf estoniacf estoniacfdecline if e_change_cf >= 0


* useful to look at the raw changes!
* gen e_change_max = e_plausible-e_implausible = .4956
* gen e_change_min1 = e_plausible - e_somewhat = .1258
* gen e_change_min2 = e_somewhat-e_implausible = .3394

eststo cfm1: mlogit e_change_cf i.estoniacf
eststo cfm2: mlogit e_change_cf i.estoniacf estoniacfdecline
eststo cfm3: mlogit e_change_cf i.estoniacf estoniacfdecline i.estoniacivilian ///
                    `demographics' `economics' `technical'

esttab 	cfm1 cfm2 cfm3 using "${MyProject}/EstoniaTableCounterfactualMlogit.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("CF1" "CF2" "CF3") ///
        title("Estonia Experiment Counterfactual (Mlogit)" \label{tab:cfm1}) ///
        eqlabel(none) longtable notes


eststo cfm4: logit  e_change_cf i.estoniacf if e_change_cf >=0
eststo cfm5: logit  e_change_cf i.estoniacf estoniacfdecline if e_change_cf >=0
eststo cfm6: logit  e_change_cf i.estoniacf estoniacfdecline i.estoniacivilian ///
                    `demographics' `economics' `technical'  if e_change_cf >=0


esttab 	cfm4 cfm5 cfm6 using "${MyProject}/EstoniaTableCounterfactualLogit.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("CF4" "CF5" "CF6") ///
        title("Estonia Experiment Counterfactual (Logit)" \label{tab:cfm4}) ///
        eqlabel(none) longtable notes

********************************************************************************
*                       Specific Strategy Analysis
********************************************************************************

eststo specm1: quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian
eststo specm2: quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
eststo specm3: quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical' `news' `knowledge'
eststo specm4: quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical' `trust' `feds'
eststo specm5: quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical' `internationalism' `feelings'
eststo specm6: quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical' `internationalism' ///
							`feelings' if attntotal == 3
							
esttab 	specm1 specm2 specm3 specm4 specm5 using "${MyProject}/EstoniaTableSpecificOlogit.tex", ///
				lab noomitted nobase varwidth(25) nodepvars compress replace ///
				mtitles("Base" "Controls" "Internet" "MI/CI" "Threat" "Knowledge") ///
        title("Estonia Experiment, Strategy Index, Ologit" \label{tab:estoniah1}) ///
        eqlabel(none) longtable notes

* * * *  * * * * * * Traditional Charts

mylabels 0(10)60, myscale(@/100) local(myla)
quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins estoniaplausible, atmeans
marginsplot, title("") ///
             subtitle({it:By Plausibility of Russian Involvement}) ///
             ylab(`myla') ///
             name(specificplausible, replace) nodraw  ///
             legend(order(1 "Nothing" 2 "Condemn" 3 "Sanctions" 4 "Espionage" ///
                          5 "Hack Drone" 6 "Cyberattack") rows(2))


mylabels 0(10)60, myscale(@/100) local(myla)
quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins estoniacivilian, atmeans
marginsplot, title("") ///
             subtitle({it:By Target Type}) ///
             ylab(`myla') ///
             name(specificivilian, replace) nodraw ///
             legend(order(1 "Nothing" 2 "Condemn" 3 "Sanctions" 4 "Espionage" ///
                          5 "Hack Drone" 6 "Cyberattack") rows(2))

grc1leg2 specificplausible specificivilian, ///
            title("Estonia Strategy Escalation (Ordinal Logit)") ///
            ycommon
gr export EstoniaEscalation.png, replace
gr export EstoniaEscalation.pdf, replace

* * * *  * * * * * * Bar Charts and Coefplot


coefplot  (specm1, label(Base, No Controls) offset(.3)) ///
         (specm2, label(Base With Controls) offset(.2)) ///
         (specm3, label(Knowledge) offset(.1)) ///
         (specm4, label(Trust)) ///
         (specm5, label(Internationalism) offset(-0.1)) /// 
		 (specm6, label(Attentive Only) offset(-0.2)) , drop(_cons) ///         
		 keep(*.estoniaplausible *.estoniacivilian) ///
         noomitted nobase xline(0) ///
         title({bf:A: Support for Retaliation}, size(medium) span) ///
         subtitle({it:Ordinal Logistic Coefficients Shown}, size(small) span) ///
         caption("N: Base = 1405, Internationalism = 1270, Attentive = 1112, Others = 1344." ///
           , size(vsmall)) ///
         headings(1.estoniaplausible = "{bf:RU Involvement Plausibility}" ///
           1.estoniacivilian = "{bf:Casualty Type}") ///
           name(coefescalation,replace) legend(rows(6) ring(0) pos(11) size(tiny))

* By Casualty Type
quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins , atmeans at(estoniacivilian == 0) post
eststo estciv00strat	   

quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins , atmeans at(estoniacivilian == 1) post
eststo estciv01strat	   

coefplot estciv00strat estciv01strat , ///
            title({bf: B: By Casualty Type}, size(medium) span) ///
			subtitle({it:Other Variables at Means}, size(small) span) ///
	recast(bar) barw(0.15) ///
	ciopts(recast(rcap) color(gs8)) citop ///
	 ylab(1 "Nothing" 2 "Condemn" 3 "Sanctions" ///
					4 "Espionage" 5 "Power Grid" 6 "Cyberattack") ///
	legend(order(1 "Military" 3 "Civilian") ring(0) pos(3)) ///
	xtitle("Predicted Probability of Choosing Each Response") ///
	name(specicitycasualtybar, replace) xlab(`myla') 		   

* By Plausibility

quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins , atmeans at(estoniaplausible == 0) post
eststo estplaus00strat	   

quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins , atmeans at(estoniaplausible == 1) post
eststo estplaus01strat	   		

quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins , atmeans at(estoniaplausible == 2) post
eststo estplaus02strat	   	


coefplot estplaus00strat estplaus01strat estplaus02strat, ///
            title({bf: C: By Plausibility of Intervention}, size(medium) span) ///
			subtitle({it:Other Variables at Means}, size(small) span) ///
	recast(bar) barw(0.15) ///
	ciopts(recast(rcap) color(gs8)) citop ///
	 ylab(1 "Nothing" 2 "Condemn" 3 "Sanctions" ///
					4 "Espionage" 5 "Power Grid" 6 "Cyberattack") ///
	legend(order(1 "Highly Implausible" 3 "Somewhat Plausible" 5 "Highly Plauisble") ring(0) pos(3)) ///
	xtitle("Predicted Probability of Choosing Each Response") ///
	name(specificstrategybar, replace) xlab(`myla') 



gr combine  specicitycasualtybar specificstrategybar, ycommon ///
			name(specificbar,replace)
			
gr combine coefescalation specificbar, rows(2)



gr export EstoniaEscalationBar.png, replace
gr export EstoniaEscalationBar.pdf, replace	
gr export EstoniaEscalationBar.eps, replace	

quietly ologit strat_specific_ordinal i.estoniaplausible i.estoniacivilian  ///
                            `demographics' `economics' `technical'
margins estoniaplausible, contrast(effects nowald)
margins estoniacivilian, contrast(effects nowald)


eststo h1m2: quietly mlogit estoniasupport_cat i.estoniacivilian i.estoniaplausible ///
                            `demographics' `economics' `technical' ///
                            , base(1)
margins estoniacivilian, contrast(effects nowald)
margins estoniaplausible, contrast(effects nowald)
